package son.nt.act4;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import son.nt.util.GoogleAnaTool;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;

public class IntentAction extends ListActivity implements OnItemClickListener{
	private static final String ACTION_CALL = "ACTION_CALL";
	private static final String ACTION_DIAL = "ACTION_DIAL";
	private static final String ACTION_EDIT = "ACTION_EDIT";
	private static final String TAG = "IntentAction";
	private Intent mIntent = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		GoogleAnaTool.track("/act4.IntentAction");
		ArrayList<String>list = new ArrayList<String>();
		list.add(ACTION_CALL);
		list.add(ACTION_DIAL);
		list.add(ACTION_EDIT);
		
		ArrayAdapter<String>adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, list);
		getListView().setAdapter(adapter);
		getListView().setOnItemClickListener(this);
	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		switch (arg2) {
		case 0:
			mIntent = new Intent(Intent.ACTION_CALL);
			mIntent.setData(Uri.parse("tel:5555-1212"));
			startActivity(mIntent);
			break;
		case 1:
			mIntent = new Intent(Intent.ACTION_DIAL);
			mIntent.setData(Uri.parse("tel:5555-1212"));
			startActivity(mIntent);
			break;
		case 2:
			mIntent = new Intent(Intent.ACTION_VIEW);
			String uriString = Environment.getExternalStorageDirectory().toString() + "/c3601_debug.txt";
			File f = new File(uriString);
			if (!f.isFile()) {
				try {
					Log.v(TAG, "create new file");
					f.createNewFile();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			Log.v(TAG, "path:" + uriString);
			mIntent.setData(Uri.parse(uriString));
			startActivity(mIntent);

		default:
			break;
		}
	}
}
